package DB.Dao.Test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import DB.Dao.BreakDown.BreakDown;
import DB.Dao.BreakDown.BreakDownDAO;
import DB.Dao.BreakStaus.BreakStatus;
import DB.Dao.BreakStaus.BreakStatusDAO;
import DB.Dao.EnterPrisUser.EnterprisUser;
import DB.Dao.EnterPrisUser.EnterprisUserDAO;
import DB.Dao.Equipment.Equipment;
import DB.Dao.Equipment.EquipmentDAO;
import junit.framework.TestCase;

public class DBtest extends TestCase {
//	public void estBreakStaus(){
//		BreakStatusDAO dao=new BreakStatusDAO();
//		List list=dao.findAll();
//		Iterator iter=list.iterator();
//		while(iter.hasNext()){ 
//			BreakStatus brea=(BreakStatus) iter.next();
//			System.out.println(brea.getStatusName());
//		}
//		
//	}
	public void testAddBreak() throws Exception{
		Equipment equipment=new Equipment();
		equipment.setEquipmentName("设备D");
		equipment.setEquipmentVersion("V2");
		EquipmentDAO equipDao=new EquipmentDAO();

		List list=equipDao.findByExample(equipment);
		//equipDao.delete(equipment);
		if(list.size()==0){
			System.out.println("size==0");
			equipDao.attachDirty(equipment);
		}
		else{
			System.out.println("sieze!=0");
			equipment=(Equipment) list.get(0);
		}
		
		System.out.println(equipment.getEquipmentName());
		System.out.println(equipment.getEquipmentVersion());
		System.out.println(equipment.getEquipmentId());
		
		
		EnterprisUser user=new EnterprisUser();
		user.setCompanyName("企业A");
		
		EnterprisUserDAO userDao=new EnterprisUserDAO();
		list=userDao.findByExample(user);
		if(list.size()==0){
			throw new Exception("user error");
		}
		user=(EnterprisUser) list.get(0);
		
		
		
		 BreakStatusDAO statusDao=new BreakStatusDAO();
		 
		 BreakStatus status=(BreakStatus)( statusDao.findByStatusName("新故障").get(0));
		
		
		
		BreakDownDAO dao=new BreakDownDAO();
		BreakDown ins=new BreakDown();
		
		ins.setAddress("address");
		ins.setDescription("description");
		ins.setEquipmentId(equipment.getEquipmentId());
		ins.setUserId(user.getUserId());
		ins.setBreakStatus(status.getStatusId());
		dao.save(ins);
		System.out.println(ins.getAddress());
		System.out.println(ins.getDescription());
		System.out.println(ins.getBreakId());
		System.out.println(ins.getBreakStatus());
		System.out.println(ins.getEquipmentId());
		System.out.println(ins.getUserId());
		
		
		
	}
}
